package com.shanghaionstar.utils;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v4.app.NotificationCompat;
import com.shanghaionstar.R;

import java.util.Random;

/**
 * Created by Yonglang Hong on 2017/1/4.
 */
public class NotificationUtil {

    public static void showNotification(Context context,String title,String msg,String page){
        NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        //设置通知的头信息
        builder.setContentTitle(title);
        //设置通知的内容信息
        builder.setContentText(msg).setColor(Color.BLACK);
        //设置通知的icon
        builder.setSmallIcon(R.drawable.onstar_icon);
        //设置通知的提示信息
        builder.setTicker(context.getString(R.string.app_name));
        builder.setAutoCancel(true);
        //设置提醒方式
        builder.setDefaults(Notification.DEFAULT_ALL);
        //设置震动的范式
        builder.setVibrate(new long[] {0,300,500,700});
        Intent targetIntent = new Intent();
        targetIntent.setComponent(new ComponentName("com.shanghaionstar", page));
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, targetIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(pendingIntent);
        Random random = new Random();
        manager.notify(random.nextInt(), builder.build());
    }

}
